﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentNHibernate.Mapping;
using SmallTune.Models;

namespace SmallTune.Mappings
{
    public class SongMap : ClassMap<Song>
    {
        public SongMap()
        {
            Id(x => x.id);
            Map(x => x.checksum);
            Map(x => x.created);
            Map(x => x.durationInSeconds);
            Map(x => x.fullTextIndex);
            Map(x => x.isPlaying);
            Map(x => x.isStarred);
            Map(x => x.lastChanged);
            Map(x => x.lastPlayed);

            ///Many songs belong to a genre.
            HasManyToMany(x => x.listOfGenres)
                .Cascade.All()
                .Table("GenresSongs");

            HasManyToMany(x => x.listOfAlbums)
                .Cascade.All()
                .Inverse()
                .Table("AlbumsSongs");

            HasManyToMany(x => x.listOfArtists)
                .Cascade.All()
                .Table("ArtistsSongs");

            ///A Song can be added to a playlist via the playlist,
            ///not vice-versa.
            HasManyToMany(x => x.listOfPlaylists)
                .Cascade.All()
                .Inverse()
                .Table("PlaylistsSongs");

            Map(x => x.path);
            Map(x => x.rating);
            Map(x => x.timesPlayed);
            Map(x => x.title);
        }
    }
}
